/**
 * @file       EventHandler.h
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#ifndef CEVENTHANDLER_H_
#define CEVENTHANDLER_H_

#include "Object.h"
#include <list>
#include <map>
#include "IEvent.h"
#include "typedefine.h"

namespace NS_LCD_AFW
{
class IEventListener;
class IEvent;
class CEventHandler;

typedef void (CEventHandler::*AFW_EventCallBack)(int, int);

class CEventHandler: public CObject
{
public:
	CEventHandler();
	virtual ~CEventHandler();

public:
	int addEventListener(IEventListener *pEventListener);
	int removeEventListener(IEventListener *&pEventListener);

	AFW_EventCallBack getCallBack(int eventId) const;
	void registerCallBack(int eventId, AFW_EventCallBack pCallBack);

public:
	virtual int handler(IEvent *pEvent);
	virtual int notify(IEvent *pEvent);
	virtual int broadcast(IEvent *pEvent);

public:
	virtual int handlerEvent(IEvent *pEvent);

private:
	void release();
	typedef std::list<IEventListener *> IEventListenerList;
	typedef std::map<int, AFW_EventCallBack> IEventMap;
private:
	IEventListenerList m_eventListenerList;
	IEventMap m_eventCallBackMap;

private:
	DISABLE_COPY_CONSTRUCTOR_AND_ASSIGN_REFERENCE(CEventHandler);

};

} /* namespace NS_LCD_AFW */
#endif /* CEVENTHANDLER_H_ */
